package br.com.ProjetoTCC_JSF.metodos;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.context.FacesContext;

public class Log implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static void accessLog(String message){
		try {
			FileWriter fw = new FileWriter("C:\\DASistemas\\Logs\\Access\\"+dateFormat(), true);
			PrintWriter pw = new PrintWriter(fw);
			pw.print(message);
			pw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	public static void systemLog(String message){
		try{
			FileWriter fw = new FileWriter("C:\\DASistemas\\Logs\\System\\"+dateFormat(), true);
			PrintWriter pw = new PrintWriter(fw);
			pw.print(message);
			pw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void systemLog(Object obj, String message){
		try{
			FileWriter fw = new FileWriter("C:\\DASistemas\\Logs\\System\\"+dateFormat(), true);
			PrintWriter pw = new PrintWriter(fw);
			pw.print(message);
			pw.print(obj);
			pw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static String hourFormat(){
		Calendar c1 = new GregorianCalendar();
		SimpleDateFormat sdfData = new SimpleDateFormat("dd.MM.yyyy");  
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");  
		String hora;
		hora=(sdfData.format(c1.getTime())+" - "+sdf.format(c1.getTime()));
		return hora;
	}
	public static String dateFormat(){
		Calendar c1 = new GregorianCalendar();
		SimpleDateFormat sdfData = new SimpleDateFormat("dd.MM.yyyy");  
		String hora;
		hora=(sdfData.format(c1.getTime()));
		return hora;
	}
	
	public static void enviaMessagemParaTela(Severity severity, String titulo, String mensagem) {
		System.out.println("Criando Mensagem...");
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(severity, titulo, mensagem));
		
		System.out.println("Enviando Mensagem...");

	}

}
